;
define(["MComponent","MLBorder","MLLayer"], function(MComponent,MLBorder,MLLayer) {
	/**
	 * 窗口面板
	 * @param {Object} background 背景
	 */
	var MPWindow = function(background) {
		this.dom = this.query("<div></div>","MPWindow");
		this.setBackground(background);
		
		//边框
		var border = new MLBorder();
		
		//批量生存层布局面板
		var list = MLLayer.list(5);
		
		//中间的面板
		var center = list[0];
		
		//顶部的面板
		var header =  list[1];
		
		//底部面板
		var footer =  list[2];
		
		//左边面板
		var left =  list[3];
		
		//右边面板
		var right =  list[4];
		
		this.init();
		
		//获得标题
		this.getHeader = function(){
			return header;
		};
		
		//获得底部
		this.getFooter = function(){
			return footer;
		}
		
		//获得左边
		this.getLeft = function(){
			return left;
		}
		
		//获得右边
		this.getRight = function(){
			return right;
		}
		
		//获得内容
		this.getContent = function(){
			return center;
		}
		
		//设置内容
		this.setContent = function(value){
			center.get(1).append(value);
			return this;
		};
		
		//设置标题高度
		this.setHeaderHeight = function(value){
			border.getNorth().setHeight(value);
			border.getNorth().setLineHeight(value);
			header.setLineHeight(value);
			border.resize();
			this.render();
			return this;
		};
		
		//设置标题内容
		this.setHeaderContent = function(value){
			header.get(1).append(value);
			return this;
		};
		
		//设置底部高度
		this.setFooterHeight = function(value){
			border.getSourth().setHeight(value);
			border.getSourth().setLineHeight(value);
			footer.setLineHeight(value);
			border.resize();
			this.render();
			return this;
		};
		
		//设置底部内容
		this.setFooterContent = function(value){
			footer.get(1).append(value);
			return this;
		};

		
		//设置左边内容
		this.setLeftContent = function(value){
			left.get(1).append(value);
			return this;
		};
		
		//设置右边内容
		this.setRightContent = function(value){
			right.get(1).append(value);
			return this;
		};
		
		//设置左边宽
		this.setLeftWidth = function(value){
			border.getWest().setWidth(value);
			border.resize();
			this.render();
			return this;
		};
		
		//设置右边宽
		this.setRightWidth = function(value){
			border.getEast().setWidth(value);
			border.resize();
			this.render();
			return this;
		};
		
		//获得边框布局
		this.getBorder = function(){
			return border;
		}
		
		/**
		 * 设置组件
		 */
		this.setComp = function(func){
			if(func && typeof func){
				for(var comp in list){
					func(list[comp]);
				}
			}
		}
		
		/**
		 * 渲染窗口
		 */
		this.render = function(){
			var that = this;
			var ie5 = function(){
				var nh = that.getBorder().getNorth().getHeight();
				var sh = that.getBorder().getSourth().getHeight();
				var ww = that.getBorder().getWest().getWidth();
				var ew = that.getBorder().getEast().getWidth();
				var aw = (that.isParentSize())? that.parent().getWidth():that.getWidth();
				var ah = (that.isParentSize())? that.parent().getHeight(): that.getHeight();
				var height = ah - nh - sh ;
				var width = aw - ew - ww ;
				that.getBorder().getCenter().setSize(width,height);
			};
			
			mofum.ieCallback(ie5,ie5,null,null,ie5);
		}
		
		this.init = function(){
			var that = this;
			this.setComp(function(comp){
				comp.setFullToParent();
				comp.put(0);
				comp.put(1);
				
				comp.setBackground = function(value){
					comp.get(0).setBackground(value);
					return comp.get(0);
				};
				
				comp.setContent = function(value){
					comp.get(1).setContent(value)
					return comp.get(1);
				};
				
				comp.setHeight = function(value) {
					that.setRightWidth(value);
					that.setLeftWidth(value);
					that.setHeaderHeight(value);
					that.setFooterHeight(value);
					var val = parseInt(value);
					comp.setStyle("height", val + "px");
					return comp;
				};
			
				comp.setWidth = function(value) {
					that.setRightWidth(value);
					that.setLeftWidth(value);
					that.setHeaderHeight(value);
					that.setFooterHeight(value);
					var val = parseInt(value);
					comp.setStyle("width", val + "px");
					return comp;
				};
				
			});
			
			border.getNorth().append(header);
			border.getSourth().append(footer);
			border.getEast().append(right);
			border.getWest().append(left);
			border.getCenter().append(center);
			
			this.append(border);
//			border.resize();
		}
		
		this.init();
	};
	mofum.extend(MPWindow, MComponent);
	return MPWindow;
});